/**
 * Copyright 2018-2020 stylefeng & fengshuonan (sn93@qq.com)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bangyu.monitor.config.datasource;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.influxdb.dto.Point;
import org.influxdb.dto.Pong;
import org.influxdb.dto.Query;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class InfluxDBConfig {

    @Value("${influxDB.url}")
    private  String url;//连接地址
    @Value("${influxDB.username}")
    private  String username;//用户名
    @Value("${influxDB.password}")
    private  String password;//密码


    @Bean
    public InfluxDB createInfluxDB() {
        InfluxDB influxDB = InfluxDBFactory.connect(url, username, password);
        influxDB.enableBatch();
        Pong pong = influxDB.ping();
        if(pong==null){
            System.out.println("influx 连接失败");
        }
//        influxDB.createDatabase("testaa");
//        Point point = Point.measurement("aa").tag("a","d").addField("v",11f).build();
//        influxDB.write("testaa","",point);
        return influxDB;
    }

    

}

